package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YwBs;
import com.ruoyi.system.service.IYwBsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 病患管理Controller
 * 
 * @author ruoyi
 * @date 2022-04-21
 */
@Controller
@RequestMapping("/system/bs")
public class YwBsController extends BaseController
{
    private String prefix = "system/bs";

    @Autowired
    private IYwBsService ywBsService;

    @RequiresPermissions("system:bs:view")
    @GetMapping()
    public String bs()
    {
        return prefix + "/bs";
    }

    /**
     * 查询病患管理列表
     */
    @RequiresPermissions("system:bs:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YwBs ywBs)
    {
        startPage();
        List<YwBs> list = ywBsService.selectYwBsList(ywBs);
        return getDataTable(list);
    }

    /**
     * 导出病患管理列表
     */
    @RequiresPermissions("system:bs:export")
    @Log(title = "病患管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YwBs ywBs)
    {
        List<YwBs> list = ywBsService.selectYwBsList(ywBs);
        ExcelUtil<YwBs> util = new ExcelUtil<YwBs>(YwBs.class);
        return util.exportExcel(list, "病患管理数据");
    }

    /**
     * 新增病患管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存病患管理
     */
    @RequiresPermissions("system:bs:add")
    @Log(title = "病患管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YwBs ywBs)
    {
        return toAjax(ywBsService.insertYwBs(ywBs));
    }

    /**
     * 修改病患管理
     */
    @RequiresPermissions("system:bs:edit")
    @GetMapping("/edit/{bsId}")
    public String edit(@PathVariable("bsId") Long bsId, ModelMap mmap)
    {
        YwBs ywBs = ywBsService.selectYwBsByBsId(bsId);
        mmap.put("ywBs", ywBs);
        return prefix + "/edit";
    }

    /**
     * 修改保存病患管理
     */
    @RequiresPermissions("system:bs:edit")
    @Log(title = "病患管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YwBs ywBs)
    {
        return toAjax(ywBsService.updateYwBs(ywBs));
    }

    /**
     * 删除病患管理
     */
    @RequiresPermissions("system:bs:remove")
    @Log(title = "病患管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ywBsService.deleteYwBsByBsIds(ids));
    }
}
